import {observable , action} from 'mobx';
import reqwest from 'reqwest';
import config from '../store/config.js';

export default class PalaceModal {
  @observable data = {
    p_id: '',
    p_name: '',
    p_g_ids: '',
    p_goodsList: '',
    p_peopleStart: '',
    p_peopleEnd: '',
    p_crowdStart: '',
    p_crowdEnd: ''
  };

  constructor(data,parent) {
    this.data = observable(data);
    this.parent = parent;
  }

  @action updatePalace(data) {
    console.log('data', data);
    reqwest({
      url: config.serverUrl +'palace.do/updatePalace',
      method: 'post',
      data: { ...data }
    }).then((data) => {
      if(data.succ) {
        this.parent.init()
      } else {
        console.log(data)
      }
    });
  }

  @action updatePalaceGoods(data) {
    console.log(data);
    reqwest({
      url: config.serverUrl +'palace.do/addPalaceGoods',
      method: 'post',
      data: { ...data }
    }).then((data) => {
      console.log(data);
      if(data.succ) {
        this.parent.init()
      } else {
        console.log(data)
      }
    });
  }
}
